package com.sina.shop.domain.goods;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.sina.shop.core.domain.Domain;
import com.sina.shop.domain.Groom;
import com.sina.shop.domain.Status;
import com.sina.shop.domain.business.Business;
import com.sina.shop.domain.card.Card;
import com.sina.shop.domain.collect.CollectGoods;
import com.sina.shop.domain.menu.Menu;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;

import javax.persistence.*;
import javax.validation.constraints.DecimalMax;
import javax.validation.constraints.DecimalMin;
import javax.validation.constraints.Min;
import java.math.BigDecimal;
import java.util.Set;

/**
 * Created with IntelliJ IDEA.
 * Description: 商品表
 * 段浩杰   2017-12-08-19:17
 */
@Entity
@Table(name = "tb_goods")
@DynamicUpdate
@DynamicInsert
public class Goods extends Domain {

    @Id
    @Column(name = "id", updatable = false)
    @GenericGenerator(name = "sequence_id", strategy = "com.sina.shop.sequence.IdGenerator")
    @GeneratedValue(generator = "sequence_id")
    @Min(1)
    private Long id;//主键

    @ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @JoinColumn(name = "bid")
    private Business business;//所属商家

    @ManyToOne(cascade = CascadeType.REMOVE, fetch = FetchType.LAZY)
    @JoinColumn(name = "mid")
    private Menu menu;//所属菜单

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "goods", fetch = FetchType.EAGER)
    private Set<GoodsPhoto> goodsPhotos;

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "goods", fetch = FetchType.LAZY)
    private Set<GoodsComment> goodsComments;

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "goods", fetch = FetchType.LAZY)
    private Set<Card> cards;

    @JsonIgnore
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "goods", fetch = FetchType.LAZY)
    private Set<CollectGoods> collectGoods;

    @Column(name = "name", length = 20)
    private String name;//商品名字

    @Column(name = "description", length = 300)
    private String description;//描述

    @Column(name = "real_price", nullable = false, precision = 12, scale = 2)
    @DecimalMin(value = "0.00")
    @DecimalMax(value = "9999999999.99")
    private BigDecimal realPrice;//折扣后价格

    @Column(name = "price", nullable = false, precision = 12, scale = 2)
    @DecimalMin(value = "0.00")
    @DecimalMax(value = "9999999999.99")
    private BigDecimal price;//原来价格

    @Column(name = "sum", length = 10)
    private Integer sum;//数量

    @Enumerated(EnumType.STRING)
    @Column(name = "is_groom", length = 10)
    private Groom isGroom;//是否推荐

    @Column(name = "credit", length = 5)
    private Integer credit;//信誉度

    @Enumerated(EnumType.STRING)
    @Column(name = "status", length = 10)
    private Status status;//表示是否可用

    public Goods() {
    }

    public Goods(Long id, String name) {
        this.id = id;
        this.name = name;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Business getBusiness() {
        return business;
    }

    public void setBusiness(Business business) {
        this.business = business;
    }

    public Menu getMenu() {
        return menu;
    }

    public void setMenu(Menu menu) {
        this.menu = menu;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public BigDecimal getRealPrice() {
        return realPrice;
    }

    public void setRealPrice(BigDecimal realPrice) {
        this.realPrice = realPrice;
    }

    public BigDecimal getPrice() {
        return price;
    }

    public void setPrice(BigDecimal price) {
        this.price = price;
    }

    public Integer getSum() {
        return sum;
    }

    public void setSum(Integer sum) {
        this.sum = sum;
    }

    public Groom getIsGroom() {
        return isGroom;
    }

    public void setIsGroom(Groom isGroom) {
        this.isGroom = isGroom;
    }

    public Integer getCredit() {
        return credit;
    }

    public void setCredit(Integer credit) {
        this.credit = credit;
    }

    public Set<GoodsPhoto> getGoodsPhotos() {
        return goodsPhotos;
    }

    public void setGoodsPhotos(Set<GoodsPhoto> goodsPhotos) {
        this.goodsPhotos = goodsPhotos;
    }

    public Set<GoodsComment> getGoodsComments() {
        return goodsComments;
    }

    public void setGoodsComments(Set<GoodsComment> goodsComments) {
        this.goodsComments = goodsComments;
    }

    public Set<Card> getCards() {
        return cards;
    }

    public void setCards(Set<Card> cards) {
        this.cards = cards;
    }

    public Set<CollectGoods> getCollectGoods() {
        return collectGoods;
    }

    public void setCollectGoods(Set<CollectGoods> collectGoods) {
        this.collectGoods = collectGoods;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
